package com.dff.jrfw.remote;

import com.bumptech.glide.load.HttpException;
import com.dff.jrfw.utils.ToastUtil;

import java.net.ConnectException;
import java.net.SocketTimeoutException;

import retrofit2.Call;
import retrofit2.Callback;

public abstract class CustomCallBack<ResponseBody> implements Callback<ResponseBody> {

    public CustomCallBack() {

    }

    @Override
    public void onFailure(Call call, Throwable t) {
        if (t instanceof ConnectException) {
            //网络连接失败
            ToastUtil.toast("当前网络不可用");
        } else if (t instanceof HttpException) {
            HttpException ex = (HttpException) t;
            ToastUtil.toast(ex.getStatusCode() + ex.getMessage());
        } else if (t instanceof SocketTimeoutException) {
            ToastUtil.toast("服务器连接超时");
        } else {
            ToastUtil.toast(t.getMessage());
        }
    }

}
